package com.atguigu.gmall.activity.receiver;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.model.activity.SeckillGoods;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rabbitmq.client.Channel;
import io.lettuce.core.dynamic.annotation.Key;
import org.checkerframework.checker.units.qual.A;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @program: gmall-parent
 * @author: Mr.Zhuo
 * @create: 2022-04-26 15:31
 **/
@Component
public class SeckillReceiver {


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConst.ROUTING_TASK_1, durable = "true", autoDelete = "false"),
            exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_TASK),
            key = {MqConst.QUEUE_TASK_1}
    ))
    public void importToRedis(Message message, Channel channel) throws IOException {

        // 首先我们需要根据条件来查询  当天是否有秒杀的库存
        QueryWrapper<SeckillGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", "1");
        queryWrapper.ge("stock_count", 0);


        // 进行消息确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
